<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="利润表" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doSearch(){
		var startDate=document.getElementById("start_date").value;
		var endDate=document.getElementById("end_date").value;
		var tsId=document.getElementById("ts_id").value;
		var type=document.getElementById("type").value;
		
		if(startDate!=null && startDate!=''){
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return;
			}
		}else{
			ShowAlert('提示框','请选择开始日期',200,100);
			return;
		}
		if(endDate!=null && endDate!=''){
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return;
			}
		}else{
			ShowAlert('提示框','请选择结束日期',200,100);
			return;
		}
		
		window.location="/finance/ProfitSearch.ihtm?start_date="+startDate+"&end_date="+endDate+"&ts_id="+tsId+"&type="+type;
	}
	
	function getSearchCondition(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var type="${type}";
		var str="start_date="+startDate+"&end_date="+endDate+"&ts_id="+tsId+"&type="+type;
		return str;
	}
	function doPrint(){
		var str=getSearchCondition();
		showWin(900,600,"/finance/ProfitSearch.ihtm?content_type=PRINT&"+str);
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function showBackDetail(baId){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_back_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(baId!=null && baId!="0" && baId!="0"){
			str=str+"&cb_ban=1&ban_acc="+baId;
		}
		showWin(1024,600,'/finance/BackCostList.ihtm?'+str);
	}
	function showCooPayDetail(baId){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_pay_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(baId!=null && baId!="0" && baId!="0"){
			str=str+"&cb_ban=1&ban_acc="+baId;
		}
		showWin(1024,600,'/finance/CooPayCostList.ihtm?'+str);
	}
	function showPurPayDetail(baId){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_pay_date=1&start_date="+startDate+"&end_date="+endDate;
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(baId!=null && baId!="0" && baId!="0"){
			str=str+"&cb_ban=1&ban_acc="+baId;
		}
		showWin(1024,600,'/finance/PurPayCostList.ihtm?'+str);
	}
	function showIncomeDetail(typeId){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_income_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_examine=1&examined=Y";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(typeId!=0){
			str=str+"&cb_income_type=1&income_type="+typeId;
		}
		showWin(1024,600,'/finance/IncomeBillSearchResult.ihtm?'+str);
	}
	function showFeeDetail(typeId){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_fee_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_examine=1&examined=Y";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		if(typeId!=0){
			str=str+"&cb_fee_type=1&fee_type="+typeId;
		}
		showWin(1024,600,'/finance/FeeBillItemSearchResult.ihtm?'+str);
	}
	function showBusList(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_order_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_examine=1&examined=Y";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1280,800,'/business/BusinessBillSearchResult.ihtm?'+str);
	}
	function showCooList(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_cooper_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_examine=1&examined=Y";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(1280,600,'/cooper/CooperBillSearchResult.ihtm?'+str);
	}
	function showOutBillList(){
		var startDate="${startDate}";
		var endDate="${endDate}";
		var tsId="${tsId}";
		var str="search_type=1&cb_out_date=1&start_date="+startDate+"&end_date="+endDate+"&cb_exa=1&exa=Y&cb_requirer=1&requirer_type=NOT_STO";
		if(tsId!="" && tsId!="0"){
			str=str+"&cb_ts=1&ts_id="+tsId;
		}
		showWin(900,600,'/storehouse/OutBillSearchResult.ihtm?'+str);
	}
</script>
</head>
<c:set var="showLink" value="Y" />
<c:if test="${fn:indexOf(currentUser.privs,';BUSI_SELF;')!=-1 || fn:indexOf(currentUser.privs,';NO_EARL_DATA;')!=-1}">
	<c:set var="showLink" value="N" />
</c:if>
<body class="sheet" style="text-align:center;">
<div class="sheet-main" style="width:860px;text-align:left;margin:auto;">
  <div class="sheet-top">
    <div class="content">
      <h2>利润表</h2>
      <p>查询当前企业经营利润，统计各个收入及支出项目</p>
    </div>
  </div>
  <div class="sheet-list">
    	<div class="search-business">
	      <div class="content">
	        <table width="100%">
	          <tbody>
	            <tr>
	              <td align="right">
					日期：
					<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" id="start_date" name="start_date" value="${startDate}">
					<img src="/images/calendar.gif" style="cursor:pointer" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this);">
					至<input class="TextBox Datetime" type="text" maxlength="15" onKeyUp="checkInput();" id="end_date" name="end_date" value="${endDate}">
					<img src="/images/calendar.gif" style="cursor:pointer" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this);">											
					<select name="ts_id" id="ts_id">
						<option value="0">==请选择帐套==</option>
						<c:forEach var="item" items="${tallySetList}">
							<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
						</c:forEach>
		  			</select>
					<select name="type" id="type">
						<option value="BILL" <c:if test="${type=='BILL'}">selected</c:if>>权责制</option>
						<option value="REC" <c:if test="${type=='REC'}">selected</c:if>>实收制</option>
					</select>
					<input type="button"  value=" 查 询" onClick="doSearch();"  class="buttom search-but">
					<input type="button"  value=" 打 印" onClick="doPrint();"  class="buttom search-print">
				   </td>
	            </tr>    
	            </tbody>      
	        </table>      	 
	      </div>
	
	   <c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_TOTA;')==-1}">
	      <div class="cue-info">
			<span>利润：${proTotal}元</span>&nbsp;&nbsp;
			<span>利润率：<strong>${proPercent}%</strong></span>&nbsp;&nbsp;
			<span>营业收入合计：${inTotal}元</span>&nbsp;&nbsp;
			<span>营业支出合计：${outTotal}元</span>&nbsp;&nbsp;
	      </div>
	    </c:if>
	      <div class="table-list">					
			  <table width="100%">
				<tr>
					<th  width="50%" ><div align="left">&nbsp;&nbsp;营业收入：${inTotal}</div></th>
					<th  width="50%" >
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%"><div align="left">&nbsp;&nbsp;营业支出：${outTotal}</div></td>
								<td style="border:0px" width="30%"><div align="right">${outTotalPer}%</div></td>
							</tr>
						</table>
					</th>
				</tr>
				
				<c:if test="${type=='REC'}">
				<tr>
					<td  width="50%" rowspan="2" valign="top">
						<div align="left">
							&nbsp;&nbsp;------&nbsp;销售收入：<c:if test="${showLink=='Y'}"><a href="javascript:showBackDetail();"></c:if>${salTotal}<c:if test="${showLink=='Y'}"></a></c:if>
							<c:forEach var="item" items="${salList}"><br/>&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showBackDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></c:forEach>
						</div>
					</td>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;材料支出：<c:if test="${showLink=='Y'}"><a href="javascript:showPurPayDetail();"></c:if>${mateTotal}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${mateTotalPer}%</div></td>
							</tr>
							<c:forEach var="item" items="${purList}">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showPurPayDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${item[3]}%</div></td>
							</tr>
							</c:forEach>
						</table>
					</td>
				</tr>
				<tr>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;外协支出：<c:if test="${showLink=='Y'}"><a href="javascript:showCooPayDetail();"></c:if>${cooTotal}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${cooTotalPer}%</div></td>
							</tr>
							<c:forEach var="item" items="${cooList}">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showCooPayDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${item[3]}%</div></td>
							</tr>
							</c:forEach>
						</table>
					</td>
				</tr>
				<tr>
					<td  width="50%" valign="top">
						<div align="left">
							&nbsp;&nbsp;------&nbsp;其他收入小计：<c:if test="${showLink=='Y'}"><a href="javascript:showIncomeDetail(0);"></c:if>${incCost}<c:if test="${showLink=='Y'}"></a></c:if>
							<c:forEach var="item" items="${incList}"><br/>&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showIncomeDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></c:forEach>
						</div>
					</td>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;费用小计：<c:if test="${showLink=='Y'}"><a href="javascript:showFeeDetail(0);"></c:if>${feeCost}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${feeTotalPer}%</div></td>
							</tr>
							<c:forEach var="item" items="${feeList}">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showFeeDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${item[3]}%</div></td>
							</tr>
							</c:forEach>
						</table>
					</td>
				</tr>
				</c:if>
				
				<c:if test="${type=='BILL'}">
				<tr>
					<td  width="50%" valign="top">
						<div align="left">
							&nbsp;&nbsp;------&nbsp;业务：<c:if test="${showLink=='Y'}"><a href="javascript:showBusList();"></c:if>${salTotal}<c:if test="${showLink=='Y'}"></a></c:if>
						</div>
					</td>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;材料：<c:if test="${showLink=='Y'}"><a href="javascript:showOutBillList();"></c:if>${mateTotal}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${mateTotalPer}%</div></td>
							</tr>
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;外协：<c:if test="${showLink=='Y'}"><a href="javascript:showCooList();"></c:if>${cooTotal}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${cooTotalPer}%</div></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td  width="50%" valign="top">
						<div align="left">
							&nbsp;&nbsp;------&nbsp;调账：${inAdj}
						</div>
					</td>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;调账：${outAdj}
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${outAdjPer}%</div></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td  width="50%" valign="top">
						<div align="left">
							&nbsp;&nbsp;------&nbsp;其他收入小计：<c:if test="${showLink=='Y'}"><a href="javascript:showIncomeDetail(0);"></c:if>${incCost}<c:if test="${showLink=='Y'}"></a></c:if>
							<c:forEach var="item" items="${incList}"><br/>&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showIncomeDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></c:forEach>
						</div>
					</td>
					<td  width="50%" valign="top">
						<table width="100%">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">
										&nbsp;&nbsp;------&nbsp;费用小计：<c:if test="${showLink=='Y'}"><a href="javascript:showFeeDetail(0);"></c:if>${feeCost}<c:if test="${showLink=='Y'}"></a></c:if>
									</div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${feeTotalPer}%</div></td>
							</tr>
							<c:forEach var="item" items="${feeList}">
							<tr>
								<td style="border:0px" width="70%">
									<div align="left">&nbsp;&nbsp;------------&nbsp;${item[2]}：<c:if test="${item[1]!='0' && showLink=='Y'}"><a href="javascript:showFeeDetail(${item[1]});"></c:if>${item[0]}<c:if test="${item[1]!='0' && showLink=='Y'}"></a></c:if></div>
								</td>
								<td style="border:0px" width="30%"><div align="right">${item[3]}%</div></td>
							</tr>
							</c:forEach>
						</table>
					</td>
				</tr>
				</c:if>
			  </table>
			</div>
		
 		</div>
  </div>
<div>
</body>
</html>